﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;

namespace Meraz.Core.Model
{
    [Serializable]
    [DataContract]
    public class TwitterMention : IEquatable<TwitterMention>
    {
        [DataMember]
        public long TweetID { get; set; }

        public int UserID { get; set; }
        public string ScreenName { get; set; }

        [DataMember]
        public bool IsRetweet { get; set; }
        [DataMember]
        public bool IsVia { get; set; }
        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public int Sequence { get; set; }

        public override bool Equals(object obj)
        {
            if (obj == null)
                return false;

            if (obj is TwitterMention)
                return Equals((TwitterMention)obj);
            return false;
        }
        public override int GetHashCode()
        {
            return TweetID.GetHashCode() ^ Name.GetHashCode();
        }
        public bool Equals(TwitterMention other)
        {
            if (other == null)
                return false;
            if (TweetID != other.TweetID)
                return false;
            return (Name == other.Name);
        }

        public void SetAttributes(string text)
        {
            IsRetweet = Regex.IsMatch(text, @"RT @" + ScreenName);
            IsVia = Regex.IsMatch(text, @"via @" + ScreenName, RegexOptions.IgnoreCase);
        }
    }
}
